package crp.core.faculty.domain.services;

import crp.core.department.domain.models.DepartmentEntity;
import crp.core.faculty.domain.models.FacultyDepartmentEntity;
import crp.core.faculty.domain.models.FacultyEntity;
import crp.core.faculty.domain.repositories.FacultyDepartmentRepository;
import crp.core.faculty.domain.repositories.FacultyRepository;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.Collection;
import java.util.stream.Stream;

@ApplicationScoped
public class FacultySearcher {
    private final FacultyRepository facultyRepository;
    private final FacultyDepartmentRepository facultyDepartmentRepository;

    @Inject
    public FacultySearcher(FacultyRepository facultyRepository,
                           FacultyDepartmentRepository facultyDepartmentRepository) {
        this.facultyRepository = facultyRepository;
        this.facultyDepartmentRepository = facultyDepartmentRepository;
    }

    public Stream<FacultyEntity> findByIds(Collection<String> ids) {
        return facultyRepository.findByIds(ids);
    }

    public Stream<DepartmentEntity> findDepartments(String facultyId) {
        return facultyDepartmentRepository.findByFacultyId(facultyId)
                .map(FacultyDepartmentEntity::getDepartment);
    }
}
